/**
 * 2025/01/01 - 2025/12/31
 */
package com.snail.server.database.engine.datasource.controller;

import com.snail.server.database.engine.datasource.dto.DataSourceAddDTO;
import com.snail.server.database.engine.datasource.dto.DataSourceModifyDTO;
import com.snail.server.database.engine.datasource.dto.DataSourceTestDTO;
import com.snail.server.database.engine.datasource.manager.DataSourceManager;
import com.snail.server.database.engine.datasource.vo.DataSourceVO;
import com.snail.starter.iam.annotation.IgnoreToken;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zgadmin
 * @date 2025/8/28 16:26
 */
@Api(tags = {"数据源管理"})
@RestController
@RequestMapping("/data-source")
public class DataSourceController {

    @Resource
    DataSourceManager datasourceManager;

    @PostMapping
    @ApiOperation("添加数据源")
    @IgnoreToken
    public Long add(@RequestBody DataSourceAddDTO datasourceAddDTO) {
        return datasourceManager.add(datasourceAddDTO);
    }

    @PutMapping
    @ApiOperation("连接测试")
    @IgnoreToken
    public Boolean test(@RequestBody DataSourceTestDTO datasourceTestDTO) {
        return datasourceManager.test(datasourceTestDTO);
    }

    @PutMapping("/{dataSourceId}")
    @ApiOperation("修改数据源")
    @IgnoreToken
    public Boolean modify(@PathVariable("dataSourceId") Long dataSourceId, @RequestBody DataSourceModifyDTO dataSourceModifyDTO) {
        return datasourceManager.modify(dataSourceId, dataSourceModifyDTO);
    }

    @GetMapping("/{dataSourceId}")
    @ApiOperation("ID查询")
    @IgnoreToken
    public DataSourceVO queryById(@PathVariable("dataSourceId") Long dataSourceId) {
        return datasourceManager.queryById(dataSourceId);
    }

    @DeleteMapping("/{dataSourceId}")
    @ApiOperation("ID删除")
    @IgnoreToken
    public Boolean delete(@PathVariable("dataSourceId") Long dataSourceId) {
        return datasourceManager.delete(dataSourceId);
    }

    @GetMapping
    @ApiOperation("所有的数据源")
    @IgnoreToken
    public List<DataSourceVO> list() {
        return datasourceManager.list();
    }

}